package cemp.api;

import cemp.common.api.reponse.RestStockAllResponse;
import cemp.entity.StockAll;
import cemp.mapper.StockAllMapper;
import cemp.service.StockCommonUtil;
import com.api.StockCommonQueryApi;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

@RestController
@RequiredArgsConstructor
public class StockCommonQueryApiImpl implements StockCommonQueryApi {

    private final StockAllMapper stockAllMapper;
    private final StockCommonUtil commonUtil;

    @Override
    public List<RestStockAllResponse> getAllStocks() {
        return stockAllMapper.selectList(null).stream().map(stockAll -> new RestStockAllResponse(stockAll.getStockCode(),stockAll.getName(),stockAll.getGl(),stockAll.getJys())).collect(Collectors.toList());
    }

    @Override
    public boolean isOpen(String date) {
        return commonUtil.isOpen(date);
    }
}
